package src;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Vector;

import src.SearchCluster;

public class CleanSMS {

	/**
	 * @author
	 */
	/* takes SMS string. tokenize it and search 
	 * each individual token in the indexed cluster. 
	 * gets head if its there else keeps it as it is 
	 * */
	
	public void clean(String sms){
		StringTokenizer st = new StringTokenizer(sms);
		SearchCluster sc = new SearchCluster();
		String result = "";
		while(st.hasMoreTokens()){
			String token = st.nextToken();
			Vector hitlist = new Vector();
			hitlist = sc.search(token);
			if(!hitlist.isEmpty()){
				String head = (String)hitlist.get(0);
				result += " "+head;
			}
			else{
				result += " "+token;
			}
		}
		System.out.println(result);
	}
	
	public static void main(String[] args) {
		File sms = new File(SMSConstant.smses);
		CleanSMS csms = new CleanSMS();
		try {
			BufferedReader reader = new BufferedReader(new FileReader(sms));
			String sentence = null;
			while((sentence = reader.readLine())!= null){
				csms.clean(sentence);
			}
			reader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e){
			e.printStackTrace();
		}
	}
}
